package com.jfshop.framework.page;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Page<E> implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5378358638623543383L;

	public static final int DEFAULT_PAGE_SIZE = 10;

	private List<E> datas;

	private int pageSize;
	private int offset;
	private int totalRecord;
	private int totalPage;

	private Map<String, Object> params = new HashMap<String, Object>();

	/**
	 * 数据总计信息
	 */
	private Object tag;

	public Page(List<E> datas, int pageSize, int offset, int totalRecord,
			int totalPage, String sort, String order) {
		super();
		this.datas = datas;
		this.pageSize = pageSize;
		this.offset = offset;
		this.totalRecord = totalRecord;
		this.totalPage = totalPage;

	}

	public Page() {
		super();
	}

	public Page(Integer pageSize, Integer currentPageNum) {

		super();

		if (pageSize != null && pageSize.compareTo(0) != 0
				&& currentPageNum != null && currentPageNum.compareTo(0) != 0) {

			this.pageSize = pageSize;
			this.offset = currentPageNum - 1;

		} else {

			this.pageSize = DEFAULT_PAGE_SIZE;
			this.offset = 0;
		}

	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public List<E> getDatas() {
		return datas;
	}

	public void setDatas(List<E> datas) {
		this.datas = datas;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public int getTotalPage() {
		if (totalRecord == 0) {
			totalPage = 0;
		} else {
			totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize
					: (totalRecord / pageSize + 1);
		}
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public Map<String, Object> getParams() {
		return params;
	}

	public void setParams(Map<String, Object> params) {
		this.params = params;
	}

	public Object getTag() {
		return tag;
	}

	public void setTag(Object tag) {
		this.tag = tag;
	}
}
